
systemParamListForM = function(){
Ext.define('systemParamModel',{
	extend:'Ext.data.Model',
	fields:[
	        	{name:'publicId',type:'String'},
	        	{name:'publicName',type:'String'},
	        	{name:'valueId',type:'string'},
	        	{name:'valueName',type:'string'},
		        {name:'publicCode',type:'string'}
		       ]
});

var selectStore  = Ext.create('Ext.data.Store',{
    data:[{valueId:"professional",valueName:"专业"},
          {valueId:"grade",valueName:"年级"},
          {valueId:"teacher job",valueName:"教师职称"},
          {valueId:"prom",valueName:"学年"},
          {valueId:"in class",valueName:"班级"}],
    fields:['valueId','valueName']            
 });

var paramTypeBox =  Ext.create('Ext.form.field.ComboBox',{
	id:'paramTypeBoxId',
	alias:'widget.lifechannelCombo',
    width: 300,
    fieldLabel: '选择要配置的类别',
    store: selectStore,
    displayField: 'valueName',
    valueField: 'valueId',
    triggerAction: 'all',
    //emptyText: '请选择...',
    blankText: '请选择',        
    queryMode:'local',
    listeners:{
    	select:function(combo,records,eopts){
    		systemParamstore.proxy.extraParams.publicCode=Ext.getCmp('paramTypeBoxId').value;
    		systemParamstore.load();
	    			/*callback: function(store,records, options ,success){ 
	    				addUsersWin.getForm().findField('itemselector-field').store=leftStore.first().list();
	    				addUsersWin.getForm().findField('itemselector-field').setValue(leftStore.first().get('isSelect'));
	    			} */
    		
    	}}
    		//Ext.Msg.alert(records[0].get('valueId'));
    
});
var systemParamstore = Ext.create('Ext.data.Store',{
	model:systemParamModel,
	autoLoad:true,
	proxy:{
		type:'ajax',
		url:'publicDictAction.action',
		reader:{
			type:'json',
			root:'list'
		},
		extraParams:{
    		publicCode:'professional'
    	}
	}
});
var checkBox = Ext.create('Ext.selection.CheckboxModel');
var grid = Ext.create('Ext.grid.GridPanel',{
	store:systemParamstore,	
	columnLines:true,
	selModel:checkBox,
	disableSelection:false,
	loadMask:true,
	columns:[
	         {text:'参数编号',width:150,dataIndex:'publicId',sortable:true},
	         {text:'参数类别中文名称',width:200,dataIndex:'publicName'},
	         {text:'参数值编码',width:200,dataIndex:'valueId'},
	         {text:'参数值中文名称',width:200,dataIndex:'valueName'},
	         {text:"参数类别识别码",width:200,dataIndex:'publicCode'}
	         ],
	autoHeight:true,
	authWidth:true,

	title:"系统参数配置信息",
	loadMask:true,
	dockedItems:[{
		dock:'top',
		xtype:'toolbar',	
		items:[paramTypeBox,'->',{
			text:'新增',
			iconCls:'Add',
			xtype:'button',
			handler:function(){
				newWindow(null);
			}
		},'-',{
			text:'删除',
			iconCls:'Decline',
			xtype:'button',
			handler:otherDelete
		}]		
	},{
		dock:'bottom',
		xtype:'label',
		html:'<div style="font-size:12px;color:red">1.双击可进行单行编辑</div>'
	}],
	listeners:
    {
        'itemdblclick': function(dataview, record, item, index, e) {
        	newWindow(record);
        	}    //单击击事件
        }
});
function newWindow(record){
	var editSystemParam = Ext.create('Ext.Window',{
		id:'editSystemParamId',
		layout:'form',
		width:400,
		height:200,
		//closeAction:'hide',
		plain:true,
		resizable : false,
		title:'系统参数信息',
		items:[{
			xtype:'textfield',
			fieldLabel:'参数编号',
			id:'publicId',
			name:'publicId',
			hidden:true,
			listeners: {
	               'afterrender': function () {
	            	   //Ext.Msg.alert("ss",record);
	                   if (record!=null){
	                	   this.setValue(record.get('publicId'));
	                   }
	               }
	           }
		},{
				   xtype:'displayfield',  
		           fieldLabel:'参数类别中文名称', 
		           id:'publicName',
		           name:'publicName',
		           //readOnly:true,
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('publicName'));
		                   }
		                   else{
		                	   var value = Ext.getCmp('paramTypeBoxId').value;
		                	   var index = selectStore.find('valueId',value); 
			        		   if(index != -1){
			        				 var r = selectStore.getAt(index);
			        				 this.setValue(r.get("valueName"));
			        			 }
		                   }
		               }
		           }
			},{
				   xtype:'displayfield',  
		           fieldLabel:'参数类别识别码', 
		           id:'publicCode',
		           name:'publicCode',  
		          // readOnly:true,
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('publicCode'));
		                   }else{
		                	   this.setValue(Ext.getCmp('paramTypeBoxId').value);
		                   }
		               }
		           }
			},{
				   xtype:'textfield',  
		           fieldLabel:'参数值编码', 
		           id:'valueId',
		           name:'valueId',  
		           allowBlank:false,  
		           blankText:'不能为空',
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('valueId'));
		                   }
		               }
		           }
			},{
				   xtype:'textfield',  
		           fieldLabel:'参数值中文名称', 
		           id:'valueName',
		           name:'valueName',  
		           allowBlank:false,  
		           blankText:'不能为空',
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('valueName'));
		                   }
		               }
		           }
			}],
		buttons : [ {
			xtype : "button",
			text : "确定",
			pressed : false,
			handler : validatorData
		},
		{
			xtype : "button",
			text : "重置",
			handler : function() {
				Ext.getCmp('valueId').setValue('');
				Ext.getCmp('valueName').setValue('');
		}
		}],
	buttonAlign : "center",
	plain:true
		
	});
	editSystemParam.show();
}
function validatorData(){ 
	var valueId = Ext.getCmp('valueId').value;
	if(valueId == "" || valueId == null){
		Ext.Msg.alert("提示","参数值不能为空");
		return;
	}
	var valueName = Ext.getCmp('valueName').value;
	if(valueName == null || valueName == ""){
		Ext.Msg.alert("提示","参数值中文名称不能为空");
		return;
	}
	var publicName = Ext.getCmp('publicName').value;
	var publicCode = Ext.getCmp('publicCode').value;
	var publicId = Ext.getCmp('publicId').value;
	var url="addSystemParamAction.action";
	if(publicId != null && publicId != ""){
		url = "updateSystemParamAction.action";
	}
	var jsonString="{'publicId':"+"'"+publicId+"'"
	+",'valueId':"+"'"+valueId+"'"
	+",'valueName':"+"'"+valueName+"'"
	+",'publicName':"+"'"+publicName+"'"
	+",'publicCode':"+"'"+publicCode+"'"
	+"}";
	Ext.Ajax.request({  
        url : url,  
        params : {  
        	jsonString : jsonString
        },  
        method : 'POST',  
        success : function(response, opts) {  
            var obj = Ext.decode(response.responseText);  
            // 当后台数据同步成功时  
            if (obj.success) {  
            	Ext.getCmp('editSystemParamId').close();
            	systemParamstore.load();
            	Ext.Msg.alert("提示","操作成功");
            } else {  
            	Ext.Msg.alert("提示",obj.msg);
            }  
        }  
    });  
}
function otherDelete() {  
    var data = grid.getSelectionModel().getSelection();  
    if (data.length == 0) {  
        Ext.Msg.alert("提示","请先选择要操作的行");  
        return;  
    } else {  
        Ext.Msg.confirm("请确认", "是否真的要删除数据？", function(button, text) {  
            if (button == "yes") {  
                var managerIds = [];  
                Ext.Array.each(data, function(record) {  
                            var managerId=record.get('publicId');  
                            managerIds.push(managerId);  
                        });
                Ext.Ajax.request({  
                    url : 'deleteSystemParamAction.action',  
                    params : {  
                    	delsString : managerIds.join(',') 
                    },  
                    method : 'POST',  
                    success : function(response, opts) {  
                        var obj = Ext.decode(response.responseText);  
                        // 当后台数据同步成功时  
                        if (obj.success) {  
                        	systemParamstore.load();
                        	Ext.Msg.alert("提示","删除成功");
                        } else {  
                        	Ext.Msg.alert("提示",obj.msg);
                        }  
                    }  
                });  
            }  
        });  
    }  
}  

function alter() {  
    
} 
Ext.getCmp('paramTypeBoxId').setValue(selectStore.data.getAt(0).get('valueId'));  
return grid;
};
